<template>
  <div class="notice-detail" style="background-color: palegoldenrod; height: 800px">
    <!-- 公告标题 -->
    <h2 class="notice-title" style="text-align: center;">{{ notice.title }}</h2>
    <!-- 公告时间 -->
    <div class="notice-time" style="opacity: 0.5; text-align: center;">{{ notice.time }}</div>
    <!-- 公告内容 -->
    <div class="notice-content" style="text-indent: 2em; font-size: larger;">{{ notice.content }}</div>
    <!-- 公告附件 -->
    <div class="notice-attachment" v-if="notice.attachment">
      <el-divider>附件下载</el-divider>
      <!-- <el-link :href="notice.attachment" target="_blank" style="margin-left: 40px;">下载附件</el-link> -->
      <div @click="downFile"><i class="el-icon-document"></i>{{ notice.attachment }}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      notice: {}
    };
  },
  created() {
    // 获取公告详情
    this.getNoticeDetail();
  },
  methods: {
    // 获取公告详情
    getNoticeDetail() {
      this.request.get('/notice/detail/' + this.$route.params.id)
        .then(response => {
          this.notice = response.data.data.list;
        })
        .catch(error => {
          console.error(error);
        });
    },
    downFile() {
      alert("开始下载")
      var url = "http://localhost:8086/downloadFile?filePath=" + this.notice.attachment
      window.open(url)
    }
  }
};
</script>
